import sqlite3


class SqlUtils:
    db = "face_id.db"
    instance = None
    def __new__(cls, *args, **kwargs):
        if cls.instance is None:
            cls.instance = super().__new__(cls)
        return cls.instance

    def __init__(self):
        try:
            self.conn = sqlite3.connect(self.db)
        except Exception as e:
            print(e)
        self.cursor = self.conn.cursor()

    def __del__(self):
        self.conn.close()

    def execute(self,sql):
        is_exec = False
        content = None
        try:
            content = self.cursor.execute(sql)
            self.conn.commit()
            is_exec =  True
        except Exception as e:
            self.conn.rollback()
            print(e)
        data = {
            "is_exec":is_exec,
            "content":content
        }
        return data


